using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using XNALibrary.Game;

namespace XNALibrary.Utils
{
    public class FpsCounter
    {
        private float updateInterval;
        float timeSinceLastUpdate;
        float framecount;
        float fps;

        public FpsCounter()
        {
            updateInterval = 1.0f;
            timeSinceLastUpdate = 0.0f;
            framecount = 0;
            fps = 0;
        }

        public string Update()
        {
            float elapsed = (float)BaseGame.gameTime.ElapsedRealTime.TotalSeconds;
            framecount++;
            timeSinceLastUpdate += elapsed;

            if (timeSinceLastUpdate > updateInterval)
            {
                fps = framecount / timeSinceLastUpdate;
                framecount = 0;
                timeSinceLastUpdate -= updateInterval;
            }
            
            return "FPS: " + fps.ToString();
        }
    }
}
